<?
/**
 * Copyright 2008 Melange.
 *
 * This file is part of Melange CMS
 *
 * @package cms
 *
 */


/**
 * Requirements
 */
require_once("mvc/action/ActionForm.php");
require_once("mvc/action/ActionMessage.php");
require_once("mvc/action/ActionMessages.php");
require_once("cms/forum/om/Topic.php");



/**
 * BaseTopicForm Class
 *
 * @category    Melange CMS
 * @package     cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 */
class BaseTopicForm extends ActionForm {


    // ----------------------------------------------------- Instance Variables


    /**
     * topic
     *
     * @var Topic 
     */
    protected $topic;


    // ----------------------------------------------------------- Constructors


    /**
     * Construct new BaseTopicForm
     */
    public function __construct() {
        $this->topic = new Topic();
    }


    // ------------------------------------------------------------- Properties


    /**
     * Get Topic
     *
     * @return Topic 
     */
    public function getTopic() {
        return $this->topic;
    }


    /**
     * Set Topic
     *
     * @param Topic  topic
     */
    public function setTopic(Topic $topic) {
        $this->topic = $topic;
    }


    // --------------------------------------------------------- Public Methods


    /**
     * Validate this form
     *
     * @return array $errors
     */
    public function validate() {

        $errors = new ActionMessages();

        if(is_null($this->getTopic()->getName()) || strlen($this->getTopic()->getName()) == 0)
            $errors->add("topic->name",
                new ActionMessage("errors.required", true, new ActionMessage("prompt.name", true)));


        if(!is_null($this->getTopic()->getName()) && strlen($this->getTopic()->getName()) > 0 && strlen($this->getTopic()->getName()) > 255)
            $errors->add("topic->name",
                new ActionMessage("errors.maxlength", true, array(
                    new ActionMessage("prompt.name", true),
                    new ActionMessage("255", false))));


        if(is_null($this->getTopic()->getBody()) || strlen($this->getTopic()->getBody()) == 0)
            $errors->add("topic->body",
                new ActionMessage("errors.required", true, new ActionMessage("prompt.body", true)));


        return $errors;
    }

}
?>